var laypage, frame;
var vm = new Vue({
	el: "#managerList",
	data: {
		load:  false,
		error: false,
		beans: [],
		page:  0,
		count: 0,
		rows:  10,
	},
	computed: {
		max: function(){
			return parseInt(this.count / this.rows + (this.count % this.rows == 0 ? 0 : 1));
		}
	}
});

function reload(page) {
	if(page != vm.page) {
		loadBean(page);
	}
}

function loadBean(curr) {
	vm.load = false;
	vm.error = false;
	var data = { "page" : curr };
	$.post("list.json", data).done(function(res){
		if(res.code == 0) {
			vm.beans = res.message.beans;
			vm.page = res.message.page;
			vm.count = res.message.count;
			if(vm.load) vm.load = true;
			laypage({
				cont: 'page',
				curr: vm.page,
				pages: vm.max,
				skip: true,
				prev: false,
				next: false,
				jump: function(obj, first){
					reload(obj.curr);
				}
			});
		}
	}).fail(function(err){
		vm.error = true;
	});
}

layui.use(['laypage', 'form'], function(){
	laypage = layui.laypage;
	loadBean(1);
});